package com.zhxh.nzpos.sell;

import java.util.ArrayList;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zhxh.nzpos.R;
import com.zhxh.nzpos.model.Buyin;

public class BuyinInfoListAdapter extends BaseAdapter {

	private ArrayList<Buyin> items;
	private LayoutInflater inflater;
	
	public BuyinInfoListAdapter(LayoutInflater inflater, ArrayList<Buyin> dealItems) {
		this.items = dealItems;
		this.inflater = inflater;
	}
	
	@Override
	public int getCount() {
		return items.size();
	}

	@Override
	public Object getItem(int position) {
		return items.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.sell_buyininfo_list_item, null);
			holder = new ViewHolder();
			holder.name = (TextView) convertView.findViewById(R.id.goods_name_tv);
			holder.date = (TextView) convertView.findViewById(R.id.input_date_tv);
			holder.sum = (TextView) convertView.findViewById(R.id.goods_number_tv);
			holder.unitPrice = (TextView) convertView.findViewById(R.id.goods_unit_price_tv);
			holder.supplier = (TextView) convertView.findViewById(R.id.goods_supplier_tv);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		Buyin item = items.get(position);
		if (item != null) {
			holder.name.setText(item.getName());
			holder.date.setText(item.getBuyinDate());
			holder.sum.setText(""+item.getCount());
			holder.unitPrice.setText(""+item.getPrice());
			holder.supplier.setText(""+item.getSupplierId());
		}
		return convertView;
	}

	static class ViewHolder {
		TextView name;
		TextView date;
		TextView sum;
		TextView unitPrice;
		TextView supplier;
	}
}
